﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Antlr.Runtime.Tree;
using Antlr.Runtime;

namespace PSLib.Parsing.Lua
{
    public class LuaTreeAdaptor : CommonTreeAdaptor
    {
        public override object Create(int tokenType, string text)
        {
            return new LuaTreeNode(this.CreateToken(tokenType, text));
        }
    }

    public static class TreeAdaptorExtension
    {
        public static object Create(this ITreeAdaptor adaptor, int tokenType, string text, IIntStream stream, int tokenStartIndex, int tokenStopIndex)
        {
            LuaTreeNode node = adaptor.Create(tokenType, text) as LuaTreeNode;
            node.TokenStartIndex = tokenStartIndex;
            node.TokenStopIndex = tokenStopIndex;
            node.Tokens = (stream as CommonTokenStream).GetTokens(tokenStartIndex, tokenStopIndex);
            return node;
        }
    }
}
